#include "stdafx.h"

#include "..\TestRunner.h"

namespace Slow
{

TESTCLASS(TestRunnerTests)
{
	class CountingReporter : public TDD::Reporter
	{
		int m_count;
	public:
		CountingReporter() : m_count(0) {}
		int GetCount() const { return m_count; }
	private:
		virtual void ForEachFailure(const TDD::TestFailure&) {}
		virtual void ForEachTest   (const TDD::UnitTestInfo&) { ++m_count; }
	};

	//TESTMETHOD(AlwaysFail)
	//{
	//	TDD_FAILURE("a temporary test that always fails");
	//}

	TESTMETHOD(NonExistantTestDll)
	{
		CountingReporter cr;
		TDD::Discriminator pred;
		TestRunner tr(pred, cr);
		TDD_VERIFY(false == tr.RunTests(L"bogus.dll"));
		TDD_VERIFY(0 == cr.GetCount());
	}

	TESTMETHOD(RunTestsInCurrentDll)
	{
		class WantFirstTestOnly : public TDD::Discriminator
		{
			bool m_first;
		public:
			WantFirstTestOnly() : m_first(true) {}
		private:
			virtual bool WantTest(const TDD::UnitTestInfo&)
			{
				if (m_first)
				{
					m_first = false;
					return true;
				}
				return false;
			}
		} wfto;

		// get self
		CString csFilename;
		::GetModuleFileName(_AtlBaseModule.GetModuleInstance(), csFilename.GetBuffer(MAX_PATH), MAX_PATH);
		csFilename.ReleaseBuffer();

		CountingReporter cr;
		TestRunner tr(wfto, cr);
		TDD_VERIFY(true == tr.RunTests(CPath(csFilename)));
		TDD_VERIFY(1 == cr.GetCount());
	}
};

}
